package com.sz.sensor.module.platform;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sz.framework.base.BaseActivity;
import com.sz.framework.utils.BarUtil;
import com.sz.framework.widget.TitleManager;
import com.sz.sensor.R;
import com.sz.sensor.adapter.MsgAdapter;
import com.sz.sensor.entity.SimpleEntity;
import com.sz.sensor.module.platform.presenter.MsgPresenter;
import com.sz.sensor.module.platform.view.MsgView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MsgActivity extends BaseActivity implements MsgView {
    @BindView(R.id.tm_title)
    TitleManager tmTitle;
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    @BindView(R.id.sfl_content)
    SmartRefreshLayout sflContent;


    private MsgPresenter presenter;
    private MsgAdapter platformAdapter;

    @Override
    public int generateLayout() {
        return R.layout.activity_msg;
    }


    @Override
    public void initTitleBar() {
        super.initTitleBar();
        tmTitle.showBack(v -> super.onBackPressed());
        tmTitle.showTitle(R.string.msg);
        tmTitle.showRight(R.drawable.icon_select, v -> showToastMessage("筛选"));
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtil.setStatusBarDarkIcon(this);

        presenter = new MsgPresenter();
        presenter.setViewer(this);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        platformAdapter = new MsgAdapter();
        rvContent.setLayoutManager(linearLayoutManager);
        rvContent.setAdapter(platformAdapter);

        sflContent.setOnRefreshListener(refreshLayout -> {
            getMsgData();
        });

        getMsgData();
    }

    @Override
    public void getMsgData() {
        presenter.getMsgData();
    }


    @Override
    public void onGetMsgData(List<SimpleEntity> entities) {
        platformAdapter.setNewData(entities);
        sflContent.finishRefresh();
    }

    @OnClick(R.id.ll_search)
    public void onViewClicked() {
        showToastMessage("搜索");
    }
}
